using System;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for DataTableProvider
/// </summary>
public partial class SqlServerProvider
{

    private SqlConnection sqlConnection;
    private SqlCommand sqlCommand;
    private SqlDataReader sqlDataReader;
    private SqlDataAdapter sqlDataAdapter;

    private string connectionString = "";
    public string ConnectionString
    {
        set { connectionString = value; }
        get { return connectionString; }
    }

    private string commandText = "";
    public string CommandText
    {
        set { commandText = value; }
        get{return commandText;}
    }
    private CommandType commandType = CommandType.Text;
    public CommandType CommandType
    {
        set { commandType = value; }
        get { return commandType; }
    }
    
    private string[] parameterCollection;
    public string[] ParameterCollection
    {
        set { parameterCollection = value; }
        get { return parameterCollection; }
    }

    private string[] valueCollection;
    public string[] ValueCollection
    {
        set { valueCollection = value; }
        get { return valueCollection; }
    }

    
    private string errorMessage = "";
    public string ErrorMessage
    {
        set { errorMessage = value; }
        get { return errorMessage; }
    }
    private int errorCode = 0;
    public int ErrorCode
    {
        set { errorCode = value; }
        get { return errorCode; }
    }
    public SqlServerProvider()
    {
        connectionString = "server=(local);" +
            "database=RecruitVietnamDb;" +
            "Integrated Security=SSPI;";
    }
    public SqlServerProvider(string conString)
    {
        connectionString = conString;
        OpenConnection();
    }
    private void OpenConnection()
    {
        if (sqlConnection == null || sqlConnection.State == ConnectionState.Closed)
        {
            sqlConnection = new SqlConnection();
            sqlConnection.ConnectionString = connectionString;
            sqlConnection.Open();
        }
    }
     
    public void CloseConnection()
    {
        
        if (sqlConnection.State == ConnectionState.Open)
        {
             sqlConnection.Close();
        }
        sqlConnection.Dispose();
    }
    public void AddParameters(SqlCommand sqlCommand)
    {
        for (int i = 0; i < parameterCollection.Length; i++)
        {
            sqlCommand.Parameters.AddWithValue(
            parameterCollection[i], valueCollection[i]);
        }
    }

    
}
